package com.haixiaoke.saas.enterprise.bill.controller;

import com.haixiaoke.saas.bill.domain.HouseBillItemMerge;
import com.haixiaoke.saas.bill.service.IHouseBillItemMergeService;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 入住账单收费项目Controller
 *
 * @author qixi
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/enterprise/bill/item/merge")
public class EnterpriseHouseBillItemMergeController extends BaseController {
    @Autowired
    private IHouseBillItemMergeService houseBillItemMergeService;

    /**
     * 查询入住账单收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseBillItemMerge houseBillItemMerge) {
        startPage();
        List<HouseBillItemMerge> list = houseBillItemMergeService.selectHouseBillItemMergeList(houseBillItemMerge);
        return getDataTable(list);
    }

    /**
     * 导出入住账单收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:export')")
    @Log(title = "入住账单收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseBillItemMerge houseBillItemMerge) {
        List<HouseBillItemMerge> list = houseBillItemMergeService.selectHouseBillItemMergeList(houseBillItemMerge);
        ExcelUtil<HouseBillItemMerge> util = new ExcelUtil<HouseBillItemMerge>(HouseBillItemMerge.class);
        util.exportExcel(response, list, "入住账单收费项目数据");
    }

    /**
     * 获取入住账单收费项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:query')")
    @GetMapping(value = "/{mergeId}")
    public AjaxResult getInfo(@PathVariable("mergeId") Long mergeId) {
        return success(houseBillItemMergeService.selectHouseBillItemMergeByMergeId(mergeId));
    }

    /**
     * 新增入住账单收费项目
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:add')")
    @Log(title = "入住账单收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseBillItemMerge houseBillItemMerge) {
        return toAjax(houseBillItemMergeService.insertHouseBillItemMerge(houseBillItemMerge));
    }

    /**
     * 修改入住账单收费项目
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:edit')")
    @Log(title = "入住账单收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseBillItemMerge houseBillItemMerge) {
        return toAjax(houseBillItemMergeService.updateHouseBillItemMerge(houseBillItemMerge));
    }

    /**
     * 删除入住账单收费项目
     */
    @PreAuthorize("@ss.hasPermi('bill:merge:remove')")
    @Log(title = "入住账单收费项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mergeIds}")
    public AjaxResult remove(@PathVariable Long[] mergeIds) {
        return toAjax(houseBillItemMergeService.deleteHouseBillItemMergeByMergeIds(mergeIds));
    }
}
